#include "StdAfx.h"
#include "znuptool.h"
#include "ZNASPClient.h"
ZNUPTool::ZNUPTool(void)
{
	m_urlPATH = _T("http://www.");
	m_urlPATH += _T("zncad.com/CATV/UPDATE/");
	m_urlinfofile = m_urlPATH + _T("ZNUPinfo.RAR");
}

ZNUPTool::~ZNUPTool(void)
{
	
}
CString ZNUPTool::Getreadme(bool & isupdata)
{
	ZNASPClient one;
	ZNUPinfo  datas;
	one.GetFileList(datas,false);


	isupdata = false;
	ZNASPClient onennenene;
	for (int i = 0 ; i < datas.m_sdatas.size(); i++)
	{
		ZNUPFileinfo * data = & datas.m_sdatas[i];

		if (data->isneedup(onennenene.GetAppPath()))
		{
			isupdata = true;
			break;
		}
	}
	CString mdstr;
	for (int i = 0 ; i < datas.m_sdatas.size();i++)
	{
		ZNUPFileinfo oneee = datas.m_sdatas[i];
		oneee.m_name = oneee.m_name.MakeLower();
		if (oneee.m_name.Find(_T("readme")) >= 0 )
		{
			mdstr = oneee.m_md5str;
		}
	}
	if (mdstr != _T(""))
	{
		CString fffff= ZTFile::CreateTempFile();
		one.downloadfile(mdstr,fffff);
		

		CFile mfile;
		if (mfile.Open(fffff,CFile::modeRead))
		{
			char indddd[24556];
			mfile.Read(&indddd,mfile.GetLength());
			indddd[mfile.GetLength()] = '\0';
			CString retstr(indddd);
			return retstr;
		}
	}

	return _T("");

}
void ZNUPTool::UPFILE(CWnd * part)
{
	ZNASPClient one;
	one.UPfiles(part);
}
void ZNUPTool::GETFILE(CWnd * part)
{
	ZNASPClient one;
	ZNUPinfo  datas;

	one.GetFileList(datas,false);
	one.downloadfiles(datas,part);

	{
		CStringArray files;
		CString path = ZTFile::GetAppPath();

		ZTFile::FindFile(files,path,_T("*.mnr"));
		for (int i = 0 ; i < files.GetSize();i++)
		{
			CString filename =  ZTFile::GetAppPath()+files[i];
			::DeleteFile(filename);
		}
	}
	{
		CStringArray files;
		CString path = ZTFile::GetAppPath();

		ZTFile::FindFile(files,path,_T("*.mnc"));
		for (int i = 0 ; i < files.GetSize();i++)
		{
			CString filename = ZTFile::GetAppPath()+ files[i];
			::DeleteFile(filename);
		}
	}


}
bool	ZNUPTool::Check()
{
	CString TEMPFILE = _T("C:\\TEMP.TXT");
	//if(GetSourceTextFile(m_urlinfofile,TEMPFILE))
	//{
	//	return true;
	//}
	return false;
}
